Interactive Introduction to Scalar Quantization

Luc Trudeau


In [14]:
%matplotlib inline

import numpy as np
from scipy.ndimage import imread
import matplotlib.pyplot as plt
from IPython.html.widgets import interact

def showImage(im):
    plt.imshow(im, cmap = plt.get_cmap('gray'), vmin = 0, vmax = 255)
    plt.title("This image has %d shades of gray." % len(np.unique(im)))
    
def quantize(step):
    showImage(np.floor(im / step) * step)

im = imread("images/tiger.png")
im = im[:,:,1]

interact(quantize, step=(1,32));